#include <iostream>
#include <string.h>
using namespace std;

template<typename T, size_t N>
using Array = T[N];
void clear(int* arr, int n) {
  memset(arr, 0, sizeof(int) * n);
}
void clear(int (*arr)[5]) {
  memset(*arr, 1, sizeof(*arr));
}
void clear(int (&arr)[5]) {
  memset(arr, -1, sizeof(arr));
}
void clear(auto& arr) {
  memset(arr, 0, sizeof(arr));
}
int main() {
  // 首地址取值
  int arr[] = {1, 2, 3, 4, 5};
  int* ptr = &(arr[0]);
  cout << "首元素地址: ";
  for (int i = 0; i < 5; i++) {
    cout << ptr[i] << ' ';
  }
  cout << endl;
  {
    // 隐式转换
    int* ptr = /*(int*)*/arr;
    cout << "数组隐式转换: ";
    for (int i = 0; i < 5; i++) {
      cout << ptr[i] << ' ';
    }
    cout << endl;
  }
  // 大小、类型输出
  cout << "数组的大小: " << sizeof(arr) << endl;
  cout << "指针的大小: " << sizeof(ptr) << endl;
  cout << "数组的类型: " << typeid(arr).name() << endl;
  cout << "指针的类型: " << typeid(ptr).name() << endl;
  {
    // 这是元素为[int 指针]的数组
    // int* ptr[5] = &arr; 
    // 真正的数组指针
    int (*ptr)[5] = &arr;
    cout << "数组指针的类型: " << typeid(ptr).name() << endl;
    cout << "数组指针解引用的类型: " << typeid(*ptr).name() << endl;
    // 可以使用范围循环
    cout << "范围循环: ";
    for (auto &x : *ptr) cout << x << ' ';
    cout << endl;
  }
  {
    // 用 using 来更明确的声明
    using Array5 = int[5];
    Array5 arr = {1, 2, 3, 4, 5};
    Array5* ptr = &arr;
    cout << "数组指针的类型: " << typeid(ptr).name() << endl;
    cout << "数组指针解引用的类型: " << typeid(*ptr).name() << endl;
    // 可以使用范围循环
    cout << "范围循环: ";
    for (auto &x : *ptr) cout << x << ' ';
    cout << endl;
  }

  clear(arr, 5);
  cout << "普通传参，memset 为 0: ";
  for (auto x: arr) cout << x << ' ';
  cout << endl;
  clear(arr);
  cout << "数组引用传参，memset 为 -1: ";
  for (auto x: arr) cout << x << ' ';
  cout << endl;
  clear(&arr);
  cout << "数组指针传参，memset 为 1: ";
  for (auto x: arr) cout << x << ' ';
  cout << endl;
  long long arr6[6] = {1, 2, 3, 4, 5, 6};
  clear(arr6);
  cout << "auto 引用传参，memset 为 0: ";
  for (auto x: arr6) cout << x << ' ';
  cout << endl;
  return 0;
}